﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace CPA
{
    class block
    {
        Texture2D[] texture;
        public bool isSolid;
        bool tile2;
        public float speed;
        public float damage;
        public int x, y, frames;
        SpriteBatch spriteBatch;
        public Rectangle position;

        public block(Texture2D[] texture, bool isSolid, float speedModifier, float dealsDamage, int x, int y, SpriteBatch spriteBatch)
            
        {

            this.texture = texture;
            this.isSolid = isSolid;
            this.speed = speedModifier;
            this.damage = dealsDamage;
            this.x = x;
            this.y = y;
            this.spriteBatch = spriteBatch;
            this.position = new Rectangle(x, y, 32, 32);
        }

        public void update() 
        {
            // Only need to swap tiles for animated tiles, such as water. They'd be provided as a 2-element array on construction.
            if (texture.Length > 1)
            {
                frames++;
                if (frames == 30 && tile2)
                {
                    frames = 0;
                    tile2 = false;
                }
                else if (frames == 30 && !tile2)
                {
                    frames = 0;
                    tile2 = true;
                }
            }
        }
        public void draw(int offsetX, int offsetY)
        {
            // Offset the drawing position to show correctly on screen
            this.position.Offset(offsetX, offsetY);

            // Draw the tile, using the correct frame for animated,
            if (this.tile2)
            {
                if (this.damage == 1)
                    spriteBatch.Draw(texture[1], this.position, Color.Red);
                else
                    spriteBatch.Draw(texture[1], this.position , Color.White);
            }
            else
            {
                if (this.damage == 1)
                    spriteBatch.Draw(texture[0], this.position, Color.Red);
                else
                    spriteBatch.Draw(texture[0], this.position, Color.White);
            }
            // Reset the offset so it doesn't stack next update 
            this.position.Offset(-offsetX, -offsetY);
        }
    }
}
